// 后端根地址，若跨域需在后端加 flask-cors
const BASE = window.location.origin;

async function apiGet(path){
  const r = await fetch(BASE + path);
  return r.json();
}
async function apiPost(path, body){
  const r = await fetch(BASE + path, {
    method:'POST',
    headers:{'Content-Type':'application/json'},
    body: JSON.stringify(body)
  });
  return r.json();
}
async function apiPostForm(path, formData){
  const r = await fetch(BASE + path, {method:'POST', body: new URLSearchParams(formData)});
  return r.json();
}
